<?php

namespace App\Models\System;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * 系统权限数据模型
 * @package App\Models
 */
class Permission extends Model
{
    use SoftDeletes;
    protected $table = 'sys_permissions';
    //主键
    protected $primaryKey = 'perm_id';
    protected $dateFormat = 'Y-m-d H:i:s';
    /**
     * 不可批量赋值的属性。
     *
     * @var array
     */
    protected $guarded = [];
    /**
     * 这个属性应该被转换为原生类型.
     *
     * @var array
     */
    protected $casts = [
        'is_public' => 'boolean',
        'is_opertion_log' => 'boolean',
    ];
    /**
     * Prepare a date for array / JSON serialization.
     *
     * @param  \DateTimeInterface  $date
     * @return string
     */
    protected function serializeDate(\DateTimeInterface $date)
    {
        return $date->format('Y-m-d H:i:s');
    }
    /**
     * 获取所有角色
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    public function roles()
    {
        return $this->belongsToMany('App\Models\System\Role','sys_permission_roles','perm_id','role_id')->withPivot('appid')->withTimestamps();
    }
}
